package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    // 根据用户id phone isDefault查询地址
    List<AddressBook> findList(AddressBook addressBook);

    // 新增地址
    @Insert("insert into address_book values (null,#{userId},#{consignee},#{sex},#{phone}," +
            "#{provinceCode},#{provinceName},#{cityCode}," +
            "#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void save(AddressBook addressBook);

    // 设置非默认地址
    @Update("update address_book set is_default = 0 where user_id = #{userId}")
    void updateByUserId(Long userId);

    // 设置默认地址之后更新数据库
    void update(AddressBook addressBook);

    // 回显地址
    @Select("select * from address_book where id = #{id}")
    AddressBook findById(Long id);

    // 删除地址
    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);
}
